import 'package:flutter/material.dart';
import 'package:my_flutter/class/RouteOutside.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});
  //测试 revert5
  //测试 revert6
  //测试 revert7
  //测试 revert8
  //测试 revert9
  @override
  Widget build(BuildContext context) {
    var routeOutside = RouteOutside();
    routeOutside.initRoute();
    return MaterialApp(
      title: 'Startup Name Generator',
      routes: routeOutside.getRoute(),
      home: const RandomWords(),
    );
  }
}

class RandomWords extends StatefulWidget {
  const RandomWords({super.key});

  @override
  createState() => RandomWordsState();
}

class RandomWordsState extends State<RandomWords> {
  var routeOutside = RouteOutside();

  RandomWordsState() {
    routeOutside.initList();
  }

  Widget getItem(int index) {
    return GestureDetector(
      child: SizedBox(
          height: 50.0,
          child: Center(
              child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              Text(
                routeOutside.getListKeys()![index],
                textAlign: TextAlign.center,
                textScaleFactor: 1.3,
              ),
            ],
          ))),
      onTap: () {
        print("index:$index");
        setState(() {
          Navigator.pushNamed(context, routeOutside.getListValues()![index]);
        });
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text('Flutter'),
        ),
        body: ListView.separated(
            separatorBuilder: (BuildContext context, int index) {
              return const Divider(color: Colors.black);
            },
            itemCount: routeOutside.getList().length,
            itemBuilder: (context, i) {
              return getItem(i);
            }));
  }
}
